package basic;

import domain.FamilyMember;
import enums.Frequency;
import utils.CommandAnalyzer;

//@author A0098891H
public class Transaction extends CRUDable{
	public static final String DEFAULT_NAME = "";
	public static final int	DEFAULT_AMOUNT = 0;
	public static final String DEFAULT_DATE = Date.getCurrentDate().toString();
	public static final String DEFAULT_BYMEM = "Household";
	public static final String DEFAULT_COMMENTS = "";
	public static final String DEFAULT_PARTYINVOLVED = "";
	public static final Frequency DEFAULT_FREQUENCY = Frequency.NO;
	
	
	//attributes
	protected String _name;
	protected double _amount;
	protected Date _date;
	protected FamilyMember _byMem;
	protected String _comments;
	protected String _partyInvolved;
	protected Frequency _frequency;
	protected Date _lastUpdateDate;
	protected double _totalAmount;

	public double get_totalAmount() {
		return _totalAmount;
	}

	public void set_totalAmount(double totalAmount) {
		if(totalAmount!=CommandAnalyzer.NA_TOTALAMOUNT)
			this._totalAmount = totalAmount;
	}

	public Date get_lastUpdateDate() {
		return _lastUpdateDate;
	}

	public void set_lastUpdateDate(Date lastUpdateDate) {
		if(!lastUpdateDate.equals(Date.NA_DATE))
			this._lastUpdateDate = lastUpdateDate;
	}

	public String get_partyInvolved() {
		return _partyInvolved;
	}

	public void set_partyInvolved(String partyInvolved) {
		if (!partyInvolved.equals(CommandAnalyzer.NA_PARTYINVOLVED))
			this._partyInvolved = partyInvolved;
	}

	/**
	 * 
	 */
	public Transaction()
	{
		_name = DEFAULT_NAME;
		_amount = DEFAULT_AMOUNT;
		_date = Date.getCurrentDate();
		_byMem = new FamilyMember(DEFAULT_BYMEM);
		_comments = DEFAULT_COMMENTS;
		_partyInvolved = DEFAULT_PARTYINVOLVED;
		_frequency = DEFAULT_FREQUENCY;
		_totalAmount = _amount;
		_lastUpdateDate = Date.getCurrentDate();
	}
	
	public Frequency get_frequency() {
		return _frequency;
	}

	public void set_frequency(Frequency frequency) {
		if (frequency != CommandAnalyzer.NA_FREQUENCY)
			this._frequency = frequency;
	}

	/**
	 * @param tran
	 */
	public Transaction(Transaction tran)
	{
		set(tran);
	}
	
	/**
	 * 
	 * @param tran
	 * @Precondition 
	 * @Postcondition 
	 */
	public void set(Transaction tran)
	{
		_name = tran._name;
		_amount = tran._amount;
		set_date(tran._date);
		set_byMem(tran._byMem);
		set_comments(tran._comments);
		set_partyInvolved(tran._partyInvolved);
		set_frequency(tran._frequency);
		set_totalAmount(tran._totalAmount);
//		System.out.println(_name + "" +_totalAmount);
		set_lastUpdateDate(tran._lastUpdateDate);
	}
	
	//getters and setters
	/**
	 * 
	 * @return
	 * @Precondition 
	 * @Postcondition 
	 */
	public String get_name() {
		return _name;
	}
	/**
	 * 
	 * @param name
	 * @Precondition 
	 * @Postcondition 
	 */
	public void set_name(String name) {
		_name = name;
	}
	/**
	 * 
	 * @return
	 * @Precondition 
	 * @Postcondition 
	 */
	public double get_amount() {
		return _amount;
	}
	/**
	 * 
	 * @param amount
	 * @Precondition 
	 * @Postcondition 
	 */
	public void set_amount(double amount) {
		_amount = amount;
	}
	
	public void addTotalAmount(double amount) {
		_totalAmount += amount;
	}
	
	public void subtractTotalAmount(double amount) {
		_totalAmount -= amount;
	}
	
	/**
	 * 
	 * @return
	 * @Precondition 
	 * @Postcondition 
	 */
	public Date get_date() {
		return _date;
	}
	/**
	 * 
	 * @param date
	 * @Precondition 
	 * @Postcondition 
	 */
	public void set_date(Date date) {
		if(!date.toString().equals(Date.NA_DATE))
			_date = date;
	}
	/**
	 * 
	 * @return
	 * @Precondition 
	 * @Postcondition 
	 */
	public FamilyMember get_byMem() {
		return _byMem;
	}
	/**
	 * 
	 * @param byMem
	 * @Precondition 
	 * @Postcondition 
	 */
	public void set_byMem(FamilyMember byMem) {
		if(!byMem.get_name().equals(CommandAnalyzer.NA_MEMBER))
			_byMem = byMem;
	}
	/**
	 * 
	 * @return
	 * @Precondition 
	 * @Postcondition 
	 */
	public String get_comments() {
		return _comments;
	}
	/**
	 * 
	 * @param comments
	 * @Precondition 
	 * @Postcondition 
	 */
	public void set_comments(String comments) {
		if(!comments.equals(CommandAnalyzer.NA_COMMENTS))
			_comments = comments;
	}
}
